#include <iostream>
#include "MinimaxingConnectNPlayer.h"
#include <cstdlib>
//#include "ProbCalculator.h"

using namespace std;


int main(int argc, char **argv) {
	int width, height, numToWin, playerNumber, timeLimit, move;
	/*ProbCalculator pc = ProbCalculator(3);
	pc.push(0);
	pc.push(0);*/


	int  debug = argc>1 ? atoi(argv[1]) :0;

	if (debug>2) {
		height = atoi(argv[2]);
		width = atoi(argv[3]);
		numToWin = atoi(argv[4]);
		playerNumber = atoi(argv[5]);
		timeLimit = atoi(argv[6]);
	} else {
		cout << "Deep Thought" << endl; // send player name
		cin >> height >> width >> numToWin >> playerNumber >> timeLimit; // read game config
	}
	bool myTurn = (playerNumber == 0) ? true : false;


	MinimaxingConnectNPlayer p = MinimaxingConnectNPlayer(height, width, numToWin, debug);

	while (true) {
		if ( myTurn ) {
			//timeoutReached = false;
			//signal(SIGALRM, timeout_handler);	// set signal handler
			//alarm(timeLimit);			// start the timer

			// call alpha-beta algorithm to get the move
			move = p.getMove();

			cout << move << endl;	// send move
		} else {
			cin >> move;		// read move
			if ( move < 0 )		// check for end
				break;
			p.setMove(move);
		}
		myTurn = !myTurn; // switch turns
	}
	return 0;
}

